const loginPage = document.querySelector('.login-page')
const closeLoginBtn = document.querySelector('#loginClose')
const loginTop = document.querySelector('.login')
const login = document.querySelector('#login')
const loginOut = document.querySelector('#loginOutBtn')
const loginedPage = document.querySelector('.logined-page')
const closeLoginedBtn = document.querySelector('#closeLoginedBtn')
const loginBtn = document.querySelector('#loginBtn')
let loginFlag = false
let isLogin = localStorage.getItem('islogin')
if(isLogin==1){
    loginFlag = true
}
var orignalSetItem = localStorage.setItem;
loginBtn.addEventListener('click',()=>{
    localStorage.setItem('islogin','1')
    loginPage.style.transform = 'translateX(-100%)'
},false)
loginOut.addEventListener('click',()=>{
    localStorage.setItem('islogin','0')
    loginedPage.style                                                                                                               .transform = 'translateX(-100%)'
},false)

localStorage.setItem = function(key,newValue){

    // var setItemEvent = new Event("setItemEvent");
    // setItemEvent.key = key;
    // setItemEvent.newValue = newValue;
    // window.dispatchEvent(setItemEvent);
    checkFun(key, newValue);
    orignalSetItem.apply(this,arguments);
};

function checkFun(key, newValue){
    if(key=='islogin'){
        if(newValue == 0){
            loginFlag= false
        }else if(newValue == 1){
            loginFlag= true
        }
    }
}
// window.addEventListener('setItemEvent',(e)=>{
//     // console.log(e)
//     if(e.key=='islogin'){
//         let _this=localStorage.getItem("islogin")
//         if(e.newValue == 0){
//             loginFlag= false
//         }else if(e.newValue == 1){
//             loginFlag= true
//         }
//     }
//     console.log(loginFlag)
// })
closeLoginedBtn.addEventListener('click',()=>{
    loginedPage.style.transform = 'translateX(-100%)'
},false)
closeLoginBtn.addEventListener('click',()=>{
    loginPage.style.transform = 'translateX(-100%)'
},false)
loginTop.addEventListener('click',()=>{
    // loginPage.style.transform = 'translateX(0%)'
    if(loginFlag){
        loginedPage.style.transform = 'translateX(0%)'
        loginPage.style.transform = 'translateX(-100%)'
    }else if(!loginFlag){
        loginPage.style.transform = 'translateX(0%)'
        loginedPage.style.transform = 'translateX(-100%)'
    }
},false)





